<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8" session="true"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>fangyin来到王者峡谷</title>
<%@include file="heard.jsp" %>

<style type="text/css">
*{margin: 5px 15px 5px 5px;}
</style>

<script type="text/javascript">

$(function(){
	
	setInterval(getTime,1000);
	showTable(0,10);
	
});


function saveUser(){
	var flag=$("#flag").val();
	var username = $("#username").val();
	var pwd = $("#pwd").val();
	
	var obj = new Object();
	if(flag=='register'){
		obj.method=flag;
		obj.username=username;
		obj.password=pwd;
	}else{
		obj.method="update";
		obj.id=flag;
		obj.username=username;
		obj.password=pwd;
		obj.deptid="1";
	}
	
	
	$.ajax({
		url: "UserServlet",
		data:obj,
        dataType: "json",
        type: "post",
        async: false,
        success: function (result, status) {
        	if(result.flag==1){
        		alert("保存成功");
        		closeBox();
        		showTable(0,10);
        	}else{
        		alert("系统或数据异常");
        	}
        }
	});
}

function showTable(index,pageSize){
	var pageNo=getPageNo(index);
	var url="UserServlet";
	var method = "getAllUser";
	var list = getInfo(url,method,pageNo,pageSize);
	var body ="";
	$(list).each(function(){
		body+="<tr>"
			 +"<td>"+this.id+"</td>"
			 +"<td>"+this.name+"</td>"
			 +"<td>"+this.createdate+"</td>"
			 +"<td><a href='javascript:void(0)' onclick='editBox("
					 +this.id
					 +",\""+this.name+"\","
					 +"\""+this.phone+"\")'>"
			 +"更改</a>"
			 +"/"
			 +"<a href='javascript:void(0)' onclick=''>删除</a></td>"
			+"</tr>";
	});
	$("#msg").html("");
	$(body).appendTo("#msg");
}


</script>
</head>
<body>
	<div id="popLayer"></div>
	<div id="popBox">
			<div class="close">
				<a href="javascript:void(0)" onclick="closeBox()">关闭</a>
			</div>
		<div class="" style="text-align:center;">
			<label >用户名：</label><input type="text" id="username" name="username"/><br>
			<label>密码：</label>&nbsp;&nbsp;&nbsp;<input type="password" id="pwd" name="password"/><br>
					<input type="hidden" id="flag" name="flag"/>
					<button onclick="saveUser()">保存</button>
		</div>
	</div>
	<h2>${username},您好。当前在线总人数为:${onLineCount}<label id="time"></label></h2>
	<hr>
	<div class="menu">
		<%@include file="menu.jsp" %>
	</div>
	
	<div class="content">
		<table>
    		<thead>
    			<tr>
        			<th>ID</th>
        			<th>用户名</th>
        			<th>注册日期</th>
        			<th>操作</th>
        		</tr>
    		</thead>
    		<tbody id="msg">
    		</tbody>
    		<tr>
    			<td colspan="4"> 
    				共<input type="text" id="total" disabled="disabled" style="width: 10px"/>页,
    				当前页数<input type="text" id="page" disabled="disabled"  style="width: 10px"/>页
    				<input type="button" class="pageUp" disabled="disabled" value="上一页"/>
    				<input type="button"class="pageDown" value="下一页">
    				每页显示条数<select class="showCount" onclick="showTable(0,this.value)">
    							<option value="5">5</option>
    							<option value="10" selected="selected">10</option>
    							<option value="20">20</option>
    						</select>
    						<button onclick="exportData('ExpImpServlet','exp',0)">导出数据</button>
    						
    			</td>
    		</tr>
    		<tr >
    			<td colspan="4">
    				<form action="ExpImpServlet" method="post" enctype="multipart/form-data">
    					<input type="file" name="file"/>
    					
    					<input type="submit" value="上传"/>
    				</form>
    			</td>
    		</tr>
		</table>
	</div>
	<input type="hidden" id="loginerId" value="${user.id}"/>
	<input type="hidden" id="loginerPwd" value="${user.phone}"/>
	<input type="hidden" id="loginerName" value="${user.name}"/>
	<input type="hidden" id="loginerDeptId" value="${user.deptId}"/>
</body>
</html>